﻿Imports System.Linq
Partial Class App_Connections
    Inherits MyUI.PageBaseApp

    Public CurrAccount As mDB.Account

    Public WithEvents GroupConsoleSearch As UI.GroupButton(Of LinkButton)
    Public WithEvents GroupConsoleDay As UI.GroupButton(Of LinkButton)

    'Protected SortGridQuery, SortGridFollStaus As UI.SortControl

#Region "PAGE"

    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load

        CurrAccount = CurrUser.CurrAccount

        GroupConsoleSearch = New UI.GroupButton(Of LinkButton)(Me.ViewState, "CONSOLE_SEARCH", "bottone-private-a")
        GroupConsoleDay = New UI.GroupButton(Of LinkButton)(Me.ViewState, "CONSOLE_DAY", "pg-count-h")

        If Not Me.IsPostBack Then
            SetDataPage()
        End If

    End Sub

    Private Sub SetDataPage()

        'SetListAccount()

        If CurrAccount IsNot Nothing Then
            SetDataConsole()
            SetDataAccountFilter()
            SetDataAccountList()
        End If

    End Sub

#End Region

#Region "CONSOLE"

    Private Sub SetDataConsole()

        'UI.Controls.ClassSet(Me.RbtSearchLink, "active", Me.SearchType = 1)
        'UI.Controls.ClassSet(Me.RbtSearchCategory, "active", Me.SearchType = 2)
        'UI.Controls.ClassSet(Me.RbtSearchHashtag, "active", Me.SearchType = 3)


        Dim Cat = CurrAccount.
            Tab_Categorize_Follower.
            REL.Categorize_Follower.Categorize.
            SetSelect("Categorize.*").
        ToDataTable()
        UI.List.Bind(Me.DdlCategories, Cat, "description", "id", "", False)

        Dim link = MyApp.EnumToDic(Of mDB._Account_Link.Type)()
        UI.List.Bind(Me.DdlLinkType, link, "value", "key", "", False)

        Dim orderby = MyApp.EnumToDic(Of OrderByType)()
        UI.List.Bind(Me.DdlOrderBy, orderby, "value", "key", "0", False)

        Dim hashtag = CurrAccount.Tab_Query_Listen.ToDataTable ' CurrAccount.Tab_Listen_Query.REL.Listen_Query.Query.SetSelect("query.*").ToDataTable
        UI.List.Bind(Me.DdlHashtag, hashtag, "query", "id", "", False)

        Dim AutoFollStatus = MyApp.EnumToDic(Of mDB.Auto_Follow_Account.StatusType)()
        UI.List.Bind(Me.DdlAutoFollStatus, AutoFollStatus, "value", "key", "", False)

        Dim query = CurrAccount.View_Query_AutoFollow.ToDataTable  'CurrAccount.Tab_Auto_Follow_Query.REL.Auto_Follow_Query.Query.SetSelect("query.id", "query.query").ToDataTable
        UI.List.Bind(Me.DdlAutoFollQuery, query, "query", "id", "", False)

        Dim gender = MyApp.EnumToDic(Of mDB.Gender_Name.Type)()
        gender.Remove(mDB.Gender_Name.Type.NOT_ASSIGNED)
        UI.List.Bind(Me.DdlGender, gender, "value", "key", "", False)

        Dim lang = DB.TAB.Language.ToList
        UI.List.Bind(Me.DdlLanguage, lang, "language", "lang_code", "", False)
        UI.List.Bind(Me.DdlLanguageNot, lang, "language", "lang_code", "", False)

        Dim business = MyApp.EnumToDic(Of mDB.Account.BusinessType)()
        business.Remove(mDB.Account.BusinessType.NOT_ASSIGNED)
        UI.List.Bind(Me.DdlBusiness, business, "value", "key", "", False)

        Dim Status = MyApp.EnumToDic(Of mDB.Account.StatusType)()
        Status.Remove(mDB.Account.StatusType.NOT_ASSIGNED)
        UI.List.Bind(Me.DdlStatus, Status, "value", "key", "", False)

        If Not Me.IsPostBack Then
            Me.GroupConsoleSearch.SelectButton = Me.RbtSearchLink
            Me.GroupConsoleDay.SelectButton = Me.RbtDayAll
            Me.DdlLinkType.SelectedValue = mDB._Account_Link.Type.FOLLOWER
        End If



    End Sub
    Private Sub SetDataAccountFilter()

        Dim f = CurrAccount.Tab_Account_Filter.ToDataTable
        UI.List.Bind(Me.DdlAccountFilter, f, "description", "id", "", False)
        Me.DdlAccountFilter.Items.Insert(0, New ListItem("-- Select  --", "0"))

        UI.List.Bind(Me.DdlOnLineList, CurrAccount.Tab_List.ToDataTable, "fullname", "id", "", False)



    End Sub
    Protected Sub BtnAddList_Click(sender As Object, e As EventArgs) Handles BtnAddList.Click

        Dim accs = CurrAccount.View_AccountLink_ByFilter(Me.GetDataFilter).
            SetSelect("account.account_code").
            Limit(1000).
        ToList(Of String)("account_code")

        Dim tw As New MyApp.Network.Twitter(CurrAccount.GetOauth)
        tw.AddList(New mDB.List With {.Fullname = Me.TxtNewList.Text}, accs)


    End Sub

    Protected Sub GroupConsoleSearch_onselected(value As String) Handles GroupConsoleSearch.Selected
        SetDataAccountList()
    End Sub


#End Region

#Region "FILTER"

    Protected Sub BtnAddFilter_Click(sender As Object, e As EventArgs) Handles BtnAddFilter.Click

        Dim f = New mDB.Account_Filter With {
            .Account_Id = CurrAccount.Id, .Description = Me.TxtNewFilter.Text
        }

        f.Filter = Me.GetDataFilter

        DB.InsertOnSubmit(f)
        DB.SubmitChanges()

        'f.SaveFilter_Data()

        SetDataAccountFilter()

    End Sub
    Protected Sub BtnRemoveFilter_Click(sender As Object, e As EventArgs) Handles BtnRemoveFilter.Click

        CurrAccount.Tab_Account_Filter.ByPK(Me.DdlAccountFilter.SelectedValue).Delete.ExecuteCommand()

        SetDataAccountFilter()
    End Sub
    Protected Sub BtnSaveFilter_Click(sender As Object, e As EventArgs) Handles BtnSaveFilter.Click

        Dim f = CurrAccount.Tab_Account_Filter.GetByPK(Me.DdlAccountFilter.SelectedValue)

        f.Filter = Me.GetDataFilter
        DB.SubmitChanges()

        SetDataAccountFilter()

    End Sub
    Protected Sub DdlAccountFilter_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlAccountFilter.SelectedIndexChanged
        Dim f = CurrAccount.Tab_Account_Filter.GetByPK(Me.DdlAccountFilter.SelectedValue)

        If f Is Nothing Then
            f = New mDB.Account_Filter
        End If

        SetDataFilter(f.Filter)

    End Sub
    Private Sub SetDataFilter(f As mDB.Account.Filter)

        Me.TxtUsername.Text = f.Username
        Me.TxtFullname.Text = f.Fullname
        Me.TxtBeginDate.Text = MyUI.Print.DateInput(f.FromDate)
        Me.TxtEndDate.Text = MyUI.Print.DateInput(f.ToDate)
        UI.List.SetSelectValues(Me.DdlLinkType, f.IdsLink)
        UI.List.SetSelectValues(Me.DdlBusiness, f.IdsBusin)
        UI.List.SetSelectValues(Me.DdlStatus, f.IdsStatus)
        UI.List.SetSelectValues(Me.DdlCategories, f.IdsCat)
        UI.List.SetSelectValues(Me.DdlGender, f.IdsGend)
        UI.List.SetSelectValues(Me.DdlLanguageNot, f.IdsLangNot)
        UI.List.SetSelectValues(Me.DdlLanguage, f.IdsLang)

    End Sub
    Private Function GetDataFilter() As mDB.Account.Filter

        Return New mDB.Account.Filter With {
            .FromDate = Utils.Conv.ToDate(Me.TxtBeginDate.Text), .ToDate = Utils.Conv.ToDate(Me.TxtEndDate.Text),
            .Username = Me.TxtUsername.Text, .Fullname = Me.TxtFullname.Text,
            .IdsLink = UI.List.GetSelectValuesInt(Me.DdlLinkType),
            .IdsBusin = UI.List.GetSelectValuesInt(Me.DdlBusiness),
            .IdsStatus = UI.List.GetSelectValuesInt(Me.DdlStatus),
            .IdsCat = UI.List.GetSelectValuesInt(Me.DdlCategories),
            .IdsGend = UI.List.GetSelectValuesInt(Me.DdlGender),
            .IdsLangNot = UI.List.GetSelectValues(Me.DdlLanguageNot),
            .IdsLang = UI.List.GetSelectValues(Me.DdlLanguage)
        }
    End Function

#End Region

#Region "ACCOUNT LIST"
    Protected Enum OrderByType
        NONE = 0
        FOLLOWER
        RANK
    End Enum


    Protected Sub SetDataAccountList()

        'Dim dt As DataTable = Nothing

        'Me.GridUsers.PageSize = 20
        'UI.Grid.Bind(Me.GridUsers, dt)

        'Me.GridAccount.PageSize = 50
        'UI.Grid.Bind(Me.GridAccount, dt)

        'Me.GridFollowStatus.PageSize = 30
        'UI.Grid.Bind(Me.GridFollowStatus, dt)

        'Me.GridFollowSummary.PageSize = 100
        'UI.Grid.Bind(Me.GridFollowSummary, dt)

        'Me.GridMessage.PageSize = 20
        'UI.Grid.Bind(Me.GridMessage, dt)

        Me.LblUserFound.Text = "-"

        Dim FromDate = Utils.Conv.ToDate(Me.TxtBeginDate.Text)
        Dim ToDate = Utils.Conv.ToDate(Me.TxtEndDate.Text)

        If FromDate = Date.MinValue Then
            FromDate = Now.AddDays(-30).Date
        End If
        If ToDate = Date.MinValue Then
            ToDate = Now.Date
        End If


        Me.PnlSearchLink.Visible = False
        Me.PnlAccountConn.Visible = False

        Me.PnlSearchHashtag.Visible = False
        Me.PnlAccountListen.Visible = False

        Me.PnlSearchAutoFollow.Visible = False
        Me.PnlAutoFollow.Visible = False

        Me.TxtFullname.Enabled = True
        Me.TxtUsername.Enabled = True

        Select Case Me.GroupConsoleSearch.SelectValue
            Case 1
                Me.PnlSearchLink.Visible = True
                Me.PnlAccountConn.Visible = True

                Dim q = CurrAccount.View_AccountLink_ByFilter(Me.GetDataFilter).
                    Limit(1000)

                Select Case DirectCast(Utils.Conv.ToInt(Me.DdlOrderBy.SelectedValue), OrderByType)
                    Case OrderByType.NONE
                    Case OrderByType.FOLLOWER
                        q.OrderBy("follower_count desc")
                    Case OrderByType.RANK
                        q.OrderBy("((follower_count /friend_count*(follower_count^1.1)) * (if(verified,1.3,1)) ) * (case status_type_id when 1 then 0.2 when 2 then 0.4 when 3 then 1.2 when 4 then 1.1 when 5 then 1 end ) desc")

                End Select


                Dim dt = q.ToDataTable()

                '-------------------------------------------------------
                ' LAYOUT
                '-------------------------------------------------------

                Dim DataBind As List(Of Object) = UI.ListData.Bind(Me.ListAccountConn, dt, {"id"})

                MyUI.Data.SetListStatusAccount(CurrAccount, UI.ListData.GetRowsList(Me.ListAccountConn), DataBind.Select(Function(o) o("account_code").ToString).ToList)
                MyUI.Data.SetListCatAccount(CurrAccount, UI.ListData.GetRowsList(Me.ListAccountConn), DataBind.Select(Function(o) CInt(o("id"))).ToList)

                If dt IsNot Nothing Then
                    Me.LblUserFound.Text = IIf(dt.Rows.Count >= 1000, "999+", dt.Rows.Count)
                End If

            Case 2
                Me.PnlSearchHashtag.Visible = True
                Me.PnlAccountListen.Visible = True

                Me.TxtFullname.Enabled = False


                Dim qQueries = CurrAccount.Tab_Query_Listen     'CurrUser.Tab_Query.BY.Query.Real_Time(1)
                Dim ids = UI.List.GetSelectValuesInt(Me.DdlHashtag) '   (From i In Me.DdlHashtag.GetSelectedIndices Select CInt(Me.DdlHashtag.Items(i).Value)).ToList
                If ids.Count <> 0 Then
                    qQueries.Where("query.id", "IN", ids)
                End If
                'Dim queries = qQueries.ToList

                Dim gruppo = New mDB.Group_Query(qQueries.ToList)

                Dim dt As DataTable = Nothing

                If gruppo.QueryList.Count > 0 Then

                    dt = gruppo.View_Account_Search(FromDate, ToDate, Me.TxtUsername.Text).
                        GroupBy("account_code").OrderBy("Post_count desc").
                        SetSelect("account_username", "account_code", "sum(Post_count) as Post_count", "account_follower_count").
                        Limit(1000).
                    ToDataTable()

                    '-------------------------------------------------------
                    ' LAYOUT
                    '-------------------------------------------------------

                    'UI.Grid.Bind(Me.GridAccount, dt)

                    Dim dtList = New List(Of List(Of Object))

                    Dim TotRows = 20
                    Dim RowCont = 0

                    For ct = 1 To Math.Ceiling(dt.Rows.Count / (TotRows * 3))
                        For ct2 = 1 To TotRows
                            Dim r = New List(Of Object)
                            For ct3 = 0 To 2
                                If dt.Rows.Count > RowCont + (TotRows * ct3) Then
                                    r.Add(dt.Rows(RowCont + (TotRows * ct3)))
                                Else
                                    r.Add(dt.NewRow)
                                End If
                            Next

                            RowCont += 1
                            dtList.Add(r)
                        Next
                        RowCont += TotRows + TotRows
                    Next

                    UI.ListData.Bind(Me.ListAccountListen, dtList)

                    '-------------------------------------
                    ' CHART

                    'Dim t1 = mDB._Query_Account.GetTrendAccount(queries, FromDate, ToDate)
                    Dim t1 = gruppo.GetTrendAccount(FromDate, ToDate)

                    Dim DataChart As New List(Of Object())
                    DataChart.Add({"data", "post", "impression"})
                    For ct = 0 To t1.Count - 1
                        DataChart.Add({MyUI.Print.DateMonthDay(t1(ct).Post_Update), t1(ct).Post_Count, t1(ct).Account_Follower_Count})
                    Next

                    Dim json = MyApp.JSONSerialize(New With {
                        .data = DataChart
                    })

                    Me.AddJScript(SF("DrawChartPostSend({0});", json))

                End If





            Case 3
                Me.PnlSearchAutoFollow.Visible = True
                Me.PnlAutoFollow.Visible = True
                Me.TxtFullname.Enabled = False

                Dim StatusIds = UI.List.GetSelectValuesInt(Me.DdlAutoFollStatus) '(From i In Me.DdlAutoFollStatus.GetSelectedIndices Select CInt(Me.DdlAutoFollStatus.Items(i).Value)).ToList
                Dim QueryIds = UI.List.GetSelectValuesInt(Me.DdlAutoFollQuery) '(From i In Me.DdlAutoFollQuery.GetSelectedIndices Select CInt(Me.DdlAutoFollQuery.Items(i).Value)).ToList

                ' STATUS

                Dim qStatus = CurrAccount.Tab_Auto_Follow_Account
                If StatusIds.Count <> 0 Then
                    qStatus.Where("status_id", "IN", StatusIds)
                End If
                If QueryIds.Count <> 0 Then
                    qStatus.Where("source_id", "IN", QueryIds)
                End If
                If FromDate > Date.MinValue Then
                    qStatus.Where("update_status_date", ">=", FromDate)
                End If
                If ToDate > Date.MinValue Then
                    qStatus.Where("update_status_date", "<", ToDate.AddDays(1))
                End If
                If Me.TxtUsername.Text <> "" Then
                    qStatus.Where("account_to_foll_username", "like", SF("%{0}%", Me.TxtUsername.Text))
                End If

                Dim dtStatus = qStatus.OrderBy("update_status_date desc").Limit(1000).ToDataTable ' pp3.SortQuery(q).ToDataTable()

                '-------------------------------------------------------
                ' LAYOUT
                '-------------------------------------------------------

                'UI.Grid.Bind(Me.GridFollowStatus, dt)

                Dim DataBind = UI.ListData.Bind(Me.ListAutoFollowAccountStatus, dtStatus, {})

                'Dim g = Me.GridFollowStatus


                For Each gr In Me.ListAutoFollowAccountStatus.Items
                    Dim dr = DataBind(UI.ListDataItem.GetIndexData(gr))
                    Dim LblStatus = UI.ListDataItem.GetControl(Of Label)(gr, "LblStatus")

                    Dim Status = DirectCast(dr("status_id"), mDB.Auto_Follow_Account.StatusType)

                    Select Case Status
                        Case mDB.Auto_Follow_Account.StatusType.PENDING, mDB.Auto_Follow_Account.StatusType.FOLLOW
                            LblStatus.ForeColor = Drawing.Color.Orange

                        Case mDB.Auto_Follow_Account.StatusType.ALREADY_FRIEND, mDB.Auto_Follow_Account.StatusType.UNFOLLOW
                            LblStatus.ForeColor = Drawing.Color.Red

                        Case mDB.Auto_Follow_Account.StatusType.ERROR
                            LblStatus.ForeColor = Drawing.Color.Gray

                        Case Else
                            LblStatus.ForeColor = Drawing.Color.Green

                    End Select


                    LblStatus.Text = Status.ToString

                Next

                ' SUMMARY

                Dim qSummary = CurrAccount.Tab_Auto_Follow_Account
                If QueryIds.Count <> 0 Then
                    qSummary.Where("source_id", "IN", QueryIds)
                End If
                If FromDate > Date.MinValue Then
                    qSummary.Where("update_status_date", ">=", FromDate)
                End If
                If ToDate > Date.MinValue Then
                    qSummary.Where("update_status_date", "<", ToDate.AddDays(1))
                End If

                Dim dtSummary = qSummary.
                    Where("status_id", "IN", New List(Of Integer) From {mDB.Auto_Follow_Account.StatusType.BECOME_FOLLOWER, mDB.Auto_Follow_Account.StatusType.UNFOLLOW}).
                    GroupBy("source_type_id", "source_id").
                    Select(
                        "source_type_id", "source_id", "source_description",
                        "sum(if(status_id = " & mDB.Auto_Follow_Account.StatusType.BECOME_FOLLOWER & ",1,0)) as count_become_follower",
                        "sum(if(status_id = " & mDB.Auto_Follow_Account.StatusType.UNFOLLOW & ",1,0)) as count_unfollower"
                    ).
                ToDataTable()

                '-------------------------------------------------------
                ' LAYOUT
                '-------------------------------------------------------


                Utils.DT.ComputeData.Compute(dtSummary, "tot", " ({'count_become_follower'} + {'count_unfollower'})")
                Utils.DT.ComputeData.Compute(dtSummary, "perc", "{'count_become_follower'} / {'tot'}  * 100 ")
                Utils.DT.ComputeData.Compute(dtSummary, "seg", " {'tot'} / {p0} * 100 ", "=sum(tot)")

                dtSummary.DefaultView.Sort = "perc desc"

                'UI.Grid.Bind(Me.GridFollowSummary, dtSum)

                UI.ListData.Bind(Me.ListAutoFollowSummary, dtSummary)

                '-------------------------------------------------------
                ' GRAFICO CONVERSIONE
                '-------------------------------------------------------

                Dim dtchar = (From d In dtSummary Order By d("count_become_follower") Descending Take 10).ToList

                Dim DataChart = New List(Of Object())
                DataChart.Add({"query", "foll", "conv"})
                For ct = 0 To dtchar.Count - 1 ' dtSum.Rows.Count - 1
                    DataChart.Add({
                        dtchar(ct)("source_description"), (dtchar(ct)("count_become_follower")), dtchar(ct)("perc")
                    })
                Next

                Dim json = MyApp.JSONSerialize(New With {
                    .data = DataChart
                })

                Me.AddJScript(SF("DrawChartPostSend2({0});", json))

                '-------------------------------------------------------
                ' GRAFICO AUTOFOLL
                '-------------------------------------------------------

                Dim qStat = CurrAccount.Tab_Auto_Follow_Account
                If QueryIds.Count <> 0 Then
                    qStat.Where("source_id", "IN", QueryIds)
                End If
                If FromDate > Date.MinValue Then
                    qStat.Where("follow_date", ">=", FromDate)
                End If
                If ToDate > Date.MinValue Then
                    qStat.Where("follow_date", "<", ToDate.AddDays(1))
                End If

                Dim dtStat = qStat.GroupBy("date(follow_date)").
                    Where("follow_date", ">", FromDate).
                    SetSelect(
                    "date(follow_date) as follow_date",
                    "sum(if(status_id = " & mDB.Auto_Follow_Account.StatusType.BECOME_FOLLOWER & ",1,0)) as count_become_follower",
                    "sum(if(status_id = " & mDB.Auto_Follow_Account.StatusType.UNFOLLOW & ",1,0)) as count_unfollow",
                    "sum(1) as count_follower"
                ).ToDataTable

                DataChart = New List(Of Object())
                DataChart.Add({"data", "Follow", "Become follower", "Unfollower"})
                For ct = 0 To dtStat.Rows.Count - 1 'Step' Each d In qt1.ToList
                    DataChart.Add({MyUI.Print.DateMonthDay(dtStat(ct)("follow_date").value), dtStat(ct)("count_follower"), dtStat(ct)("count_become_follower"), dtStat(ct)("count_unfollow")})
                Next

                json = MyApp.JSONSerialize(New With {
                    .data = DataChart
                })

                Me.AddJScript(SF("DrawChartAutoFollow({0});", json))


            Case 4

                Dim q = DB.TAB.Message_Post.
                    Join("message_post", "post_code", "message_post.reply_to_post_code", "mess_reply", "").
                    Join("account", "id", "mess_reply.account_id").
                    Where("message_post.account_id", "=", CurrAccount.Id).
                    Where("message_post.reply_to_post_code", "<>", "").
                    OrderBy("pubb_date desc").
                    SetSelect("Message_Post.*", "account.*", "mess_reply.post_text as  reply_post_text")


                Dim dt = q.
                ToDataTable()



                'UI.Grid.Bind(Me.GridMessage, dt)

        End Select


        Me.UpPAccountConn.Update()
        Me.UpPAccountListen.Update()
        Me.UpPAutoFollow.Update()




    End Sub

    Protected Function GetImageGenderType(b As mDB.Account.BusinessType, g As mDB.Gender_Name.Type) As String

        If b = GloukDB.Account.BusinessType.BUSINESS Then
            Return "business.png"
        Else
            If g = GloukDB.Gender_Name.Type.MALE Then
                Return "man.png"
            End If
            If g = GloukDB.Gender_Name.Type.FEMALE Then
                Return "woman.png"
            End If

        End If

        Return ""
    End Function
    Protected Function GetImageStatus(b As mDB.Account.StatusType) As String

        Select Case b
            Case GloukDB.Account.StatusType.FAKE
                Return "conn-fake.png"
            Case GloukDB.Account.StatusType.INACTIVE
                Return "conn-inactive.png"
            Case GloukDB.Account.StatusType.LOW_ACTIVITY, GloukDB.Account.StatusType.MEDIUM_ACTIVITY, GloukDB.Account.StatusType.HIGHT_ACTIVITY
                Return "conn-good.png"
            Case Else
                Return ""
        End Select

    End Function

    Protected Sub ChkExcluded_CheckedChanged(sender As Object, e As EventArgs)

        Dim chk As CheckBox = sender
        Dim row = UI.ListDataItem.GetRow(sender)
        Dim id = UI.ListDataItem.GetKey(row)

        'Dim link = CurrAccount.Tab_Account_Link(GloukDB.Account_Link.Type.FOLLOWER, id).ToObj
        Dim link = CurrAccount._Tab_Account_Link(mDB._Account_Link.Type.FOLLOWER, id).ToObj
        If link IsNot Nothing Then
            link.Excluded = chk.Checked

            DB.SubmitChanges()
        End If




    End Sub

    Protected Sub BtnExport_Click(sender As Object, e As EventArgs) Handles BtnExport.Click

        SetDataAccountList()

    End Sub


#End Region


End Class

'Public Class GroupButton_old

'    Public Property CacheState As Object
'    Public Property group As String
'    Public Property cssactive As String


'    Private Buttons As New List(Of Button)
'    Private p As Page

'    Public ReadOnly Property SelectValue() As String
'        Get
'            Return Me.SelectButton.CommandArgument
'        End Get
'    End Property

'    Public Property SelectButtonID() As String
'        Get
'            Return Me.CacheState("_GROUP_" & Me.group)
'        End Get
'        Set(ByVal value As String)
'            Me.CacheState("_GROUP_" & Me.group) = value
'        End Set
'    End Property

'    Public Property SelectButton() As Button
'        Get
'            Return (From b In Me.Buttons Where b.ID = Me.SelectButtonID).FirstOrDefault
'        End Get
'        Set(value As Button)
'            Me.SelectButtonID = value.ID

'            SetDataButtonList()

'        End Set
'    End Property

'    Public Event Selected(value As String)


'    Sub New(cache As Object, group As String, cssactive As String)


'        Me.p = HttpContext.Current.CurrentHandler
'        Me.CacheState = cache
'        Me.group = group
'        Me.cssactive = cssactive

'        Buttons = UI.Controls.FindCommandControls(Of Button)(Me.p.Controls, group)

'        For Each b In Buttons
'            AddHandler b.Click, AddressOf BntExport_Click
'        Next
'        SetDataButtonList()

'    End Sub

'    Private Sub SetDataButtonList()

'        For Each b In Buttons
'            UI.Controls.ClassSet(b, cssactive, b.ID = Me.SelectButtonID)
'        Next

'    End Sub


'    Protected Sub BntExport_Click(sender As Object, e As EventArgs)

'        Me.SelectButton = sender
'        RaiseEvent Selected(Me.SelectValue)

'    End Sub

'End Class

'Public Class GroupButton(Of tres As {IButtonControl, WebControl})

'    Public Property CacheState As Object
'    Public Property group As String
'    Public Property cssactive As String


'    Private Buttons As New List(Of tres)
'    Private p As Page

'    Public ReadOnly Property SelectValue() As String
'        Get
'            Return Me.SelectButton.CommandArgument
'        End Get
'    End Property

'    Public Property SelectButtonID() As String
'        Get
'            Return Me.CacheState("_GROUP_" & Me.group)
'        End Get
'        Set(ByVal value As String)
'            Me.CacheState("_GROUP_" & Me.group) = value
'        End Set
'    End Property

'    Public Property SelectButton() As tres
'        Get
'            Return (From b In Me.Buttons Where b.ID = Me.SelectButtonID).FirstOrDefault
'        End Get
'        Set(value As tres)
'            Me.SelectButtonID = value.ID

'            SetDataButtonList()

'        End Set
'    End Property

'    Public Event Selected(value As String)


'    Sub New(cache As Object, group As String, cssactive As String)


'        Me.p = HttpContext.Current.CurrentHandler
'        Me.CacheState = cache
'        Me.group = group
'        Me.cssactive = cssactive

'        Buttons = UI.Controls.FindCommandControls(Of tres)(Me.p.Controls, group)

'        For Each b In Buttons
'            AddHandler b.Click, AddressOf BntExport_Click
'        Next
'        SetDataButtonList()

'    End Sub

'    Private Sub SetDataButtonList()

'        For Each b In Buttons
'            UI.Controls.ClassSet(b, cssactive, b.ID = Me.SelectButtonID)
'        Next

'    End Sub


'    Protected Sub BntExport_Click(sender As Object, e As EventArgs)

'        Me.SelectButton = sender
'        RaiseEvent Selected(Me.SelectValue)

'    End Sub

'End Class







